package com.xiaoshuidi.cloud.module.bpm.enums.swo;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.xiaoshuidi.cloud.framework.common.exception.ErrorCode;
import com.xiaoshuidi.cloud.framework.common.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 服务工单 - 服务类型枚举
 */
@Getter
@AllArgsConstructor
public enum SwoServiceStatusEnum {


    PENDING_ORDERS("待接单", 1),
    IN_PROGRESS("进行中", 2),
    COMPLETED("已完成", 3);

    private String name;
    private Integer value;

    public static String getNameByValue(Integer value) {
        SwoServiceStatusEnum swoServiceTypeEnum = Arrays.stream(SwoServiceStatusEnum.values()).filter(p -> p.getValue().equals(value)).findFirst().orElse(null);
        if(ObjectUtil.isEmpty(swoServiceTypeEnum)){
            throw new ServiceException(new ErrorCode(100322, StrUtil.format("服务工单服务类型枚举value{}不存在",value)));
        }
        return swoServiceTypeEnum.getName();    }
}
